package com.ruoyi.caiwu.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.caiwu.domain.AccountingVoucherSummary;
import com.ruoyi.caiwu.service.IAccountingVoucherSummaryService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 凭证常用摘要Controller
 *
 * @author ruoyi
 * @date 2025-02-25
 */
@RestController
@RequestMapping("/summary")
public class AccountingVoucherSummaryController extends BaseController
{
    @Autowired
    private IAccountingVoucherSummaryService accountingVoucherSummaryService;

    /**
     * 查询凭证常用摘要列表
     */
    @RequiresPermissions("caiwu:summary:list")
    @GetMapping("/list")
    public TableDataInfo list(AccountingVoucherSummary accountingVoucherSummary)
    {
        startPage();
        List<AccountingVoucherSummary> list = accountingVoucherSummaryService.selectAccountingVoucherSummaryList(accountingVoucherSummary);
        return getDataTable(list);
    }

    /**
     * 导出凭证常用摘要列表
     */
    @RequiresPermissions("caiwu:summary:export")
    @Log(title = "凭证常用摘要", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccountingVoucherSummary accountingVoucherSummary)
    {
        List<AccountingVoucherSummary> list = accountingVoucherSummaryService.selectAccountingVoucherSummaryList(accountingVoucherSummary);
        ExcelUtil<AccountingVoucherSummary> util = new ExcelUtil<AccountingVoucherSummary>(AccountingVoucherSummary.class);
        util.exportExcel(response, list, "凭证常用摘要数据");
    }

    /**
     * 获取凭证常用摘要详细信息
     */
    @RequiresPermissions("caiwu:summary:query")
    @GetMapping(value = "/{summaryId}")
    public AjaxResult getInfo(@PathVariable("summaryId") Long summaryId)
    {
        return success(accountingVoucherSummaryService.selectAccountingVoucherSummaryBySummaryId(summaryId));
    }

    /**
     * 新增凭证常用摘要
     */
    @RequiresPermissions("caiwu:summary:add")
    @Log(title = "凭证常用摘要", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccountingVoucherSummary accountingVoucherSummary)
    {
        return toAjax(accountingVoucherSummaryService.insertAccountingVoucherSummary(accountingVoucherSummary));
    }

    /**
     * 修改凭证常用摘要
     */
    @RequiresPermissions("caiwu:summary:edit")
    @Log(title = "凭证常用摘要", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccountingVoucherSummary accountingVoucherSummary)
    {
        return toAjax(accountingVoucherSummaryService.updateAccountingVoucherSummary(accountingVoucherSummary));
    }

    /**
     * 删除凭证常用摘要
     */
    @RequiresPermissions("caiwu:summary:remove")
    @Log(title = "凭证常用摘要", businessType = BusinessType.DELETE)
	@DeleteMapping("/{summaryIds}")
    public AjaxResult remove(@PathVariable Long[] summaryIds)
    {
        return toAjax(accountingVoucherSummaryService.deleteAccountingVoucherSummaryBySummaryIds(summaryIds));
    }
}
